package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.framework.shiro.util.AuthorizationUtils;
import com.ruoyi.system.domain.Officialstudent;
import com.ruoyi.system.domain.SysListenStudent;
import com.ruoyi.system.service.SysListenStudentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: Admin
 * @date: 2021/11/3 10:41
 * @description:
 */
@Controller
@RequestMapping("/system/listen")
public class SysListenStudentController extends BaseController {
    @Autowired
    SysListenStudentService listenStudentService;
    private String prefix = "system/zxsgl/Listen";
    @RequiresPermissions("system:stxs:view")
    @GetMapping()
    public String listen(){
        return prefix+"/ListenStudent";
    }
    @RequiresPermissions("system:stxs:view")
    @PostMapping ("/list")
    @ResponseBody
    public TableDataInfo list(SysListenStudent sysListenStudent){
        System.out.println(sysListenStudent);

        Long userId = ShiroUtils.getUserId();
        startPage();
        List<SysListenStudent> sysListenStudents = listenStudentService.selectStudentAll(sysListenStudent);
        return getDataTable(sysListenStudents);
    }
    @GetMapping("/add")
    @RequiresPermissions("system:stxs:add")

    public String add(){

        return prefix+"/add";
    }
    @PostMapping("/add")
    @RequiresPermissions("system:stxs:add")
    @ResponseBody
    public AjaxResult pAdd( SysListenStudent sysListenStudent){
        System.out.println(sysListenStudent);
        int i = listenStudentService.insertAll(sysListenStudent);
        System.out.println(i);
        return toAjax(i);

    }
    // 删除方法
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Integer ids)
    {
        System.out.println(ids);
        return toAjax(listenStudentService.deleteUserByIds(ids));
    }
    // 修改状态
    @PostMapping("/Status")
    @ResponseBody
    public AjaxResult status(Integer ids)
    {
        System.out.println(ids);
        return toAjax(listenStudentService.updateListenStatusByListenIdAfter(ids));
    }

    /**
     * 修改
     * @param
     * @param mmap
     * @return
     */
    @GetMapping("/edit/{listenId}")
    public String edit(@PathVariable("listenId") Integer listenId, ModelMap mmap, HttpSession session)
    {
        Object listenId1 = session.getAttribute("listenId");
        if(listenId1!=null){
            session.removeAttribute("listenId");
        }
        session.setAttribute("listenId",listenId);
        System.out.println(listenId);
        SysListenStudent sysListenStudent = listenStudentService.searchAllByListenIdAfter(listenId);
        mmap.addAttribute("SysListenStudent",sysListenStudent);
        return prefix + "/edit";
    }
    /**
     * 修改保存正式学生
     */
    @RequiresPermissions("system:stxs:edit")
    @Log(title = "正式学生", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(String  data,
                               HttpSession session)
    {
        System.out.println(data);
        Integer listenId = (Integer) session.getAttribute("listenId");
        int i = listenStudentService.updateListenRemarksByListenId(listenId, data);
        System.out.println(data);
        return toAjax(i);
    }
}
